--[[ 编码: WMS-20-01 名称: 入库单-创建前 作者:HAN 日期:2025-1-29 级别:固定 (说明本段代码在项目中不太会变化) 函数: BeforeDataObjCreate 功能: 1)生成到入库单编码 S_NO 格式:IO2301-00001 更改记录: --]] wms_base = require ("wms_base") function BeforeDataObjCreate ( strLuaDEID ) local nRet, strRetInfo -- step1: 获取当前【入库单】编码 nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_NO","S_FACTORY" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local obj_attrs = json.decode( strRetInfo ) local strCode = obj_attrs[1].value local factory = lua.Get_StrAttrValue( obj_attrs[2].value ) -- 如果工厂标识为空,系统自动赋值当前操作者的单位为 S_FACTORY if ( factory == '') then local strUserLogin, strUserName nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员信息失败! "..strUserLogin ) end -- 获取当前操作人员的单位编码,作为工厂标识 nRet, strRetInfo = mobox.getUserSectionUnit( strUserLogin ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员所属单位失败! "..strRetInfo ) end if ( strRetInfo ~= '' ) then local orgInfo = json.decode( strRetInfo ) factory = orgInfo.company_code else nRet, factory = wms_base.Get_sConst2( strLuaDEID, "默认工厂标识" ) if ( nRet ~= 0 ) then lua.Stop( strLuaDEID, "系统无法获取常量'默认工厂标识'") return end end end -- 如果上架单编码为空,生成上架单编码 if ( strCode == '' ) then local strHeader = 'IO'..os.date("%y%m")..'-' nRet,strCode = mobox.getSerialNumber( "入库单", strHeader, 5 ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '申请入库单编码失败!'..strCode ) end end -- 设置信息 local attr_value = {} attr_value[1] = lua.KeyValueObj( "S_NO", strCode ) attr_value[2] = lua.KeyValueObj( "S_FACTORY", factory ) nRet, strRetInfo = mobox.setCurEditDataObjAttr( strLuaDEID, lua.table2str(attr_value) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "设置【入库单】信息失败! "..strRetInfo ) end end